<?php
    require_once 'adminmenu.php';
    $content = new Models_Tags();
    if(isset($_POST['add']))
    {
        $content->setTagToArticle($id, $tagId);
    } elseif (isset ($_POST['remove'])) {
        $content->removeTagFromArticle($id, $tagId);
    }
    $articleContent = new Models_Articles();
    $article = $articleContent->getArticle($id);
    $tags = $content->getAllTags();
    $articleTags = $content->getArticleTags($id);
?>
<div class="well">
    <h3><a href="/<?php $content->printPath(); ?>articles/show/<?php echo $id; ?>"><?php echo $article['title']; ?></h3>
</div>
<div class="row">
    <div class="span9">
        <div class="well">
            <form class="form-horizontal" action="/<?php echo $content->path; ?>articles/addtagto/<?php echo $id; ?>" method="POST">
                <fieldset>
                  <legend>Add tag:</legend>
                  <div class="control-group">
                    <label class="control-label">Tags:</label>
                    <div class="controls">
                      <select size="10" name="tag" required>
                          <?php
                              foreach ($tags as $tag)
                              {
                                    echo "<option value=" . $tag['id']
                                               . ">"
                                               . $tag['name'] 
                                               . "</option>";
                              }
                          ?>
                      </select>
                    </div>
                  </div>
                  <div class="form-actions">
                    <button class="btn btn-primary" type="submit" name="add">Add >></button>
                    <button class="btn" type="reset">Clear</button>
                  </div>
                </fieldset>
              </form>
        </div>
    </div>
    <div class="span9">
        <div class="well">
            <form class="form-horizontal" action="/<?php echo $content->path; ?>articles/addtagto/<?php echo $id; ?>" method="POST">
                <fieldset>
                  <legend>Remove tag:</legend>
                  <div class="control-group">
                    <label class="control-label">Tags:</label>
                    <div class="controls">
                      <select size="10" name="tag" required>
                          <?php
                              foreach ($articleTags as $tag)
                              {
                                  echo "<option value=" . $tag['id']
                                                        . ">"
                                                        . $tag['name'] 
                                                        . "</option>";
                              }
                          ?>
                      </select>
                    </div>
                  </div>
                  <div class="form-actions">
                    <button class="btn btn-primary" type="submit" name="remove"><< Remove</button>
                    <button class="btn" type="reset">Clear</button>
                  </div>
                </fieldset>
              </form>
        </div>
    </div>
</div>